<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-9-5
 * Time: 下午12:55
 * To change this template use File | Settings | File Templates.
 */
class tool extends MY_Controller
{
    public function test()
    {
        //$this->load->model('/analysis/tu_cc', 'tuCc');
        //$data = array('file_name' => FCPATH.'test.htm', 'source_id' => 505050);
        //$this->tuCc->analysis($data);
    }
    /**
     * 删除首页静态文件
     */
    public function updateIndex()
    {
        system('rm -rf '.FCPATH.'index.html');
    }

    /**
     * 删除资源分类静态文件
     */
    public function updateResourceCategory()
    {
        system('rm -rf '.FCPATH.'category/*');
    }

    /**
     * 删除资源静态文件
     */
    public function updateResource()
    {
        system('rm -rf '.FCPATH.'resource/*');
    }

    /**
     * 截图 绽放到指定大小
     */
    public function cutImage()
    {
        set_time_limit(0);
        //copyImg('源文件', 350, 420, '目标文件');

        $start = 1;
        $end = 400000;
        //$end = 20;
        $config = array('dir' => '/data/www/dy1010/web/html/images/', 'crawl_type' => 'image');
        //$config = array('dir' => 'D:\wamp\www\dy1010/web/html/images/', 'crawl_type' => 'image');

        for ($i = $start; $i<=$end; $i++)
        {
            $fileName = $config['dir'].intToPath($i).$i.'.jpg';
            echo $i."\n";
            if (!file_exists($fileName) || filesize($fileName) < 3500) continue;

            $path = image_path($i);
            if (!is_dir($path)) {
                rMkDir($path);
            }

            $targetFileName = $path.$i.'.jpg';

            copyImg($fileName, 242, 345, $targetFileName);
        }
    }

    /**
     * 分析数据库所有二级分类
     */
    public function parse_type()
    {
        set_time_limit(0);
        $this->load->database();
        $loop = range(1,10);
        foreach($loop as $class)
        {
            $query = $this->db->query("select `type` from mp_movie where class = '{$class}' group by `type`")->result_array();
            //echo count($query),'<br>';continue;
            foreach ($query as $v) {
                $tmp = explode('|', $v['type']);
                foreach($tmp as $name)
                {
                    $this->db->insert('category', array('pid'=>$class,'name'=>trim($name)), true);
                }
            }
        }
    }

    /**
     * 检查资源是否有下载地址，如果没有直接删除
     */
    public function isDownloadAddressAndDelete()
    {
        $limit = 1000;
        $start = 0;
        $end   = 400000;

        $this->load->model('movie');

        for ($i = $start; $i < $end; $i = $i + $limit)
        {
            //echo $limit.'--'.$i."\n";//continue;
            $field = 'id';
            $data = $this->movie->getMovieList($field, $limit, $i);
            //print_r($data);exit;

            foreach ($data as $v)
            {
                $downInfo = array();
                $mId = intval($v['id']);

                if (empty ($mId)) continue;

                $downInfo = $this->movie->getDownLoad($mId, 2);

                if (empty ($downInfo) || !is_array($downInfo)) {
                    $s = $this->movie->deleteResource($mId);
                    if (!$s) {
                        exit($mId);
                    }
                    echo $mId."\n";
                }
            }
            unset ($data);
        }
    }
}
